<%--                                                                       --%>
<%-- Copyright (c) 2003-2005 BroadVision, Inc.  All rights reserved.       --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries. Additionally, IONA    --%>
<%-- and Orbix are trademarks of IONA Technologies, Ltd.  RSA, MD5, and    --%>
<%-- RC2 are trademarks of RSA Data Security, Inc.                         --%>
<%--                                                                       --%>

<%@ page import="com.broadvision.ssp.util.TableConstants" %>

<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/struts-html-el.tld" prefix="html-el" %>
<%@ taglib uri="/WEB-INF/struts-bean-el.tld" prefix="bean-el" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<%
  String ctxPath = request.getContextPath();
%>

<%@ include file="/mc/common/encodeURL.jsp" %>

<script language="JavaScript">
  var catoid = -1;
  var fromAction = "";
  var fromActionParam = "";
  function onSelection(param)
  {
    var firstSplit = param.split('&');
    var secondSplit = firstSplit[0].split('=');
    catoid = secondSplit[1];
    if (fromAction == "processMoveOne") {
      doProcessMoveOneAction(fromActionParam);
    }
    return true;
  }

  function browserProcessCategory()
  {
    var bparam = "contentTypeId=<%= TableConstants.SSP_PROCESS_CONTENT_TYPE %>&categoryID=0&action=expandCategory&rootNodeOID=0&currentNodeId=-1";
    var str = encodeURL('bp/categoryBrowser.do', bparam);
    var qualifier = window.open(str, "bpmCategoryPicker",
      "directories=no,height=300,width=450,left=50,top=50,resizable=yes,scrollbars=yes,location=no,menubar=no,status=no,toolbar=no,");
    if (qualifier != null) {
        if (qualifier.opener == null)
          qualifier.opener = self;
        qualifier.focus();
    }
  }

  function doProcessEditAction(oid) {
    document.processMyListForm.processOid.value = oid;
    document.processMyListForm.action = '<c:url value="/bp/processEdit.do"/>';
    document.processMyListForm.submit();
  }

  function processMoveOne(oid) {
    fromAction = "processMoveOne";
    fromActionParam = oid;
    browserProcessCategory();
  }
  
  function doProcessMoveOneAction(oid) {
    if (catoid != null && catoid != "") {
      document.processMyListForm.destinedCategoryOid.value = catoid;
      document.processMyListForm.oneOnly.value = true;
      document.processMyListForm.processOid.value = oid;
      document.processMyListForm.action = '<c:url value="/bp/processMove.do"/>';
      document.processMyListForm.forwardAction.value = '/bp/processMyList.do';
      document.processMyListForm.submit();
    }
  }

  function doProcessOnOffOneAction(oid, online) {
    document.processMyListForm.oneOnly.value = true;
    document.processMyListForm.processOid.value = oid;
    document.processMyListForm.action = '<c:url value="/bp/processOnOff.do"/>';
    document.processMyListForm.setOnlineStatus.value = online;
    document.processMyListForm.forwardAction.value = '/bp/processMyList.do';
    document.processMyListForm.submit();
  }

  function doProcessOnOffAction(myform, online) {
    myform.oneOnly.value = false;
    myform.action = '<c:url value="/bp/processOnOff.do"/>';
    myform.setOnlineStatus.value = online;
    myform.forwardAction.value = '/bp/processMyList.do';
    myform.submit();
  }

  function check(field, button) {
    var SelectAllTxt = '<bean-el:message key="button.selectAll" bundle="bp.messages"/>';
    var UnselectAllTxt = '<bean-el:message key="button.unselectAll" bundle="bp.messages"/>';
    if (field == null) {
      button.value = SelectAllTxt;
    }
    var checkflag = "false";
    if (button.value == SelectAllTxt) {
      checkflag = "false";
    }
    if (button.value == UnselectAllTxt) {
      checkflag = "true";
    }
    var max = field.length;
    if (max > 1) {
      if (checkflag == "false") {
        for (i = 0; i < max; i++) {
          field[i].checked = true;
        }
        button.value = UnselectAllTxt;
      } else {
        for (i = 0; i < max; i++) {
          field[i].checked = false;
        }
        button.value = SelectAllTxt;
      }
    } else {
      if (checkflag == "false") {
        field.checked = true;
        button.value = UnselectAllTxt;
      } else {
        field.checked = false;
        button.value = SelectAllTxt;
      }
    }
  }
  
  function update(field, button) {
    var SelectAllTxt = '<bean-el:message key="button.selectAll" bundle="bp.messages"/>';
    var UnselectAllTxt = '<bean-el:message key="button.unselectAll" bundle="bp.messages"/>';
    if (field == null) {
      button.value = SelectAllTxt;
    }
    var checkflag = "false";
    if (button.value == SelectAllTxt) {
      checkflag = "false";
    }
    if (button.value == UnselectAllTxt) {
      checkflag = "true";
    }
    var max = field.length;
    if (max > 1) {
      if (checkflag == "false") {
        for (i = 0; i < max; i++) {
          if (field[i].checked == false) {
            return;
          }
        }
        button.value = UnselectAllTxt;
      } else {
        for (i = 0; i < max; i++) {
          if (field[i].checked == true) {
            return;
          }
        }
        button.value = SelectAllTxt;
      }
    } else {
      if (checkflag == "false") {
        if (field.checked == true) {
          button.value = UnselectAllTxt;
        }
      } else {
        if (field.checked == false) {
          button.value = SelectAllTxt;
        }
      }
    }
  }

  function isAnyChecked(field, alertmsg, confirmmsg) {
    if (field == null) {
      if (alertmsg != null && alertmsg.length > 0) {
        alert(alertmsg);
      }
      return false;
    }
    else if (field.length == null) {
      if (field.checked == false) {
        if (alertmsg != null && alertmsg.length > 0) {
          alert(alertmsg);
        }
        return false;
      }
      else {
        if (confirmmsg != null && confirmmsg.length > 0) {
          return confirm(confirmmsg);
        }
        else {
          return true;
        }
      }
    }
    else {
      for (var j = 0; j < field.length; j++) {
        if (field[j].checked) {
          if (confirmmsg != null && confirmmsg.length > 0) {
            return confirm(confirmmsg);
          }
          else {
            return true;
          }
        }
      }
      if (alertmsg != null && alertmsg.length > 0) {
        alert(alertmsg);
      }
      return false;
    }
  }

</script>

<c:set var="editImg">
<img src="<%= ctxPath %>/mc/images/action/icon_edit.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean-el:message key="image.alt.edit" bundle="mc.messages"/>" title="<bean-el:message key="image.alt.edit" bundle="mc.messages"/>">
</c:set>
<c:set var="offlineImg">
<img src="<%= ctxPath %>/mc/images/action/icon_offline.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean-el:message key="image.alt.setOffline" bundle="mc.messages"/>" title="<bean-el:message key="image.alt.setOffline" bundle="mc.messages"/>">
</c:set>
<c:set var="onlineImg">
<img src="<%= ctxPath %>/mc/images/action/icon_online.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean-el:message key="image.alt.setOnline" bundle="mc.messages"/>" title="<bean-el:message key="image.alt.setOnline" bundle="mc.messages"/>">
</c:set>
<c:set var="moveImg">
<img src="<%= ctxPath %>/mc/images/action/icon_move.gif" width="15" height="15" border="0" class="actionIcon" alt='<bean-el:message key="image.alt.move" bundle="bp.messages"/>' title='<bean-el:message key="image.alt.move" bundle="bp.messages"/>'>
</c:set>

<html-el:form action="/bp/processMyList.do">
<input type="hidden" name="destinedCategoryOid"/>
<input type="hidden" name="processOid"/>
<input type="hidden" name="oneOnly"/>
<input type="hidden" name="setOnlineStatus"/>
<input type="hidden" name="forwardAction"/>
<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" summary="content area">
  <tr>
    <td valign="top" width="100%">
      <div class="pageTitle"><bean-el:message key="bp.process.processMyModels.title" bundle="bp.messages"/></div>
      <div class="errorMessage"><html-el:errors bundle="bp.messages"/></div>
      <logic:empty name="processMyListView" property="processes">
        <bean:define id="processMyCount" value="0"/>
      </logic:empty>
      <logic:notEmpty name="processMyListView" property="processes">
        <bean:size id="processMyCount" name="processMyListView" property="processes"/> 
      </logic:notEmpty>
      <div class="pageSubtitle">
        <span class="left">
          <logic:empty name="processMyListView" property="processes">
            <bean-el:message key="bp.process.processMyModels.myProcessModels" arg0="0" bundle="bp.messages"/>
          </logic:empty>
          <logic:notEmpty name="processMyListView" property="processes">
            <bean-el:message key="bp.process.processMyModels.myProcessModels" arg0="${processMyCount}" bundle="bp.messages"/>
          </logic:notEmpty>
        </span>
        <span class="right">&nbsp;</span>
      </div>
      <logic:empty name="processMyListView" property="processes">
        <table class="dataTable" border="0" cellspacing="1" cellpadding="2" summary="my list table" width="100%">
          <tr class="listHeader"> 
            <th id="Checkboxes">&nbsp;</th>
            <th id="Name" align="left">
              <bean-el:message key="header.processModel" bundle="bp.messages"/>
            </th>
            <th id="LastModifiedDate" align="left">
              <bean-el:message key="header.lastModifiedDate" bundle="bp.messages"/>
            </th>
            <th id="Manager" align="left"><bean-el:message key="header.processModelManager" bundle="bp.messages"/></th>
            <th id="Status" align="left"><bean-el:message key="header.status" bundle="bp.messages"/></th>
            <th id="Actions" align="left" nowrap><bean-el:message key="header.actions" bundle="bp.messages"/></th>
          </tr>
          <tr class="listEven">
            <td align="center" colspan="6">
              <bean-el:message key="bp.process.noMyProcess" bundle="bp.messages"/>
            </td>
          </tr>
        </table>
      </logic:empty>
      <logic:notEmpty name="processMyListView" property="processes">
        <div class="globalButtonWrap">
          <input type="button" name="selectAll" class="globalButton" 
            onClick="check(this.form.processOids, this);" value="<bean-el:message key="button.selectAll" bundle="bp.messages"/>">
          <input type="button" name="setOnline" class="globalButton" 
            onClick="if (isAnyChecked(this.form.processOids, '<bean-el:message key="bp.process.alert.atLeastOne" bundle="bp.messages"/>', '')) doProcessOnOffAction(this.form, true);" 
            value='<bean-el:message key="button.setOnline" bundle="bp.messages"/>'>
          <input type="button" name="setOffline" class="globalButton" 
            onClick="if (isAnyChecked(this.form.processOids, '<bean-el:message key="bp.process.alert.atLeastOne" bundle="bp.messages"/>', '')) doProcessOnOffAction(this.form, false);" 
            value='<bean-el:message key="button.setOffline" bundle="bp.messages"/>'>
        </div>
        <table class="dataTable" border="0" cellspacing="1" cellpadding="2" summary="my list table" width="100%">
          <tr class="listHeader"> 
            <th id="Checkboxes">&nbsp;</th>
            <th id="Name" align="left">
              <logic:notEqual name="processMyListForm" property="sortBy" value="0">
                <html-el:link page="/bp/processMyList.do?sortBy=0">
                  <bean-el:message key="header.processModel" bundle="bp.messages"/>
                </html-el:link>
              </logic:notEqual>
              <logic:equal name="processMyListForm" property="sortBy" value="0">
                <bean-el:message key="header.processModel" bundle="bp.messages"/>&nbsp;
                <bean-el:message key="bp.process.processMyModels.sortSymbol" bundle="bp.messages"/>
              </logic:equal>
            </th>
            <th id="LastModifiedDate" align="left">
              <logic:notEqual name="processMyListForm" property="sortBy" value="1">
                <html-el:link page="/bp/processMyList.do?sortBy=1">
                  <bean-el:message key="header.lastModifiedDate" bundle="bp.messages"/>
                </html-el:link>
              </logic:notEqual>
              <logic:equal name="processMyListForm" property="sortBy" value="1">
                <bean-el:message key="header.lastModifiedDate" bundle="bp.messages"/>&nbsp;
                <bean-el:message key="bp.process.processMyModels.sortSymbol" bundle="bp.messages"/>
              </logic:equal>
            </th>
            <th id="Manager" align="left"><bean-el:message key="header.processModelManager" bundle="bp.messages"/></th>
            <th id="Status" align="left"><bean-el:message key="header.status" bundle="bp.messages"/></th>
            <th id="Actions" align="left" nowrap><bean-el:message key="header.actions" bundle="bp.messages"/></th>
          </tr>
          <logic:iterate id="process" name="processMyListView" property="processes" indexId="i">
            <tr class="<%=i.intValue() % 2 == 0 ? "listEven" : "listOdd" %>">
              <td headers="Checkboxes">
                <input type="checkbox" name="processOids"
                  onClick="update(this.form.processOids, this.form.selectAll);" 
                  value='<c:out value="${process.map.oid}"/>'>
              </td>
              <td headers="Name">
                <html-el:link page="/bp/processView.do" paramId="processOid" paramName="process" paramProperty="oid">
                  <c:out value="${process.map.name}"/>
                </html-el:link>
              </td>
              <td headers="LastModifiedDate">
                <bean:write name="process" property="lastModifiedDate" formatKey="format.datetime.short" bundle="mc.messages"/>
              </td>
              <td headers="Manager">
                <logic:notEqual name="process" property="managerId" value="-1">
                  <c:out value="${process.map.managerFullName}"/>
                </logic:notEqual>
                <logic:equal name="process" property="managerId" value="-1">
                  &nbsp;
                </logic:equal>
              </td>
              <td headers="Status">
                <logic:equal name="process" property="status" value="0">
                  <bean-el:message key="bp.process.status.inDeployment" bundle="bp.messages"/>
                </logic:equal>
                <logic:equal name="process" property="status" value="1">
                  <logic:equal name="process" property="online" value="true">
                    <bean-el:message key="bp.process.status.online" bundle="bp.messages"/>
                  </logic:equal>
                  <logic:equal name="process" property="online" value="false">
                    <bean-el:message key="bp.process.status.offline" bundle="bp.messages"/>
                  </logic:equal>
                </logic:equal>
                <logic:equal name="process" property="status" value="2">
                  <bean-el:message key="bp.process.status.error" bundle="bp.messages"/>
                </logic:equal>
                <logic:equal name="process" property="status" value="3">
                  <bean-el:message key="bp.process.status.toBeConfigured" bundle="bp.messages"/>
                </logic:equal>
              </td>
              <td nowrap align="left" headers="Actions">
                <a href='#' onclick="doProcessEditAction('<c:out value="${process.map.oid}"/>');"><c:out value='${editImg}' escapeXml="false"/></a>
                <logic:equal name="process" property="status" value="1">
                  <logic:equal name="process" property="online" value="false">
                    <a href='#' onclick="doProcessOnOffOneAction('<c:out value="${process.map.oid}"/>', true);"><c:out value='${onlineImg}' escapeXml="false"/></a>
                  </logic:equal>
                  <logic:equal name="process" property="online" value="true">
                    <a href='#' onclick="doProcessOnOffOneAction('<c:out value="${process.map.oid}"/>', false);"><c:out value='${offlineImg}' escapeXml="false"/></a>
                  </logic:equal>
                </logic:equal>
                <a href='#' onclick="processMoveOne('<c:out value="${process.map.oid}"/>');"><c:out value='${moveImg}' escapeXml="false"/></a>
              </td>
            </tr>
          </logic:iterate>
        </table>
      </logic:notEmpty>
    </td>
  </tr>
</table>
</html-el:form>

